<?php
       
    session_start();

    //echo 'entro <br/>';

    // Conexion
    include '../../BD/conexion.php';
    echo 'se conecto <br/>';
    
    // Recibe las Variables
    $email	= $_POST['email'];
    $pass	= $_POST['pass'];
    $nombre;
    $apellido;

   if(isset($email) && !empty($email) &&
    isset($pass) && !empty($pass)){
        $sel=pg_query("SELECT id_empleado FROM mails_empleados WHERE email='$email' ");
        $row = pg_fetch_row($sel);
       // echo $row[0];
        $id_empleado = $row[0];
        $sel = pg_query("SELECT nombre,apellido,passwd,id_empleado FROM empleados WHERE id_empleado='$id_empleado' ");
       //   $row = pg_fetch_row($sel);
       // echo $row[0];
            $sesion=pg_fetch_array($sel);

            if($pass==$sesion['passwd']){
                $_SESSION['username']=$email;
                $_SESSION['password']=$pass;
                $_SESSION['nombre']=$sesion['nombre'];
                $_SESSION['apellido']=$sesion['apellido'];
                 $_SESSION['id_empleado']=$sesion['id_empleado'];/*
                $_SESSION['ci']=$sesion['Ci'];
                $_SESSION['sexo']=$sesion['Sexo'];
                $_SESSION['permisos']=$sesion['Permisos'];*/
                //echo "correo coincide";
                
                header("Location:../../index.php");
     
            }else{
                //echo "Password incorrecto";
                header("Location:../../login.php?errorCode=2&errorType=1");       
            }
            
        } else{
       //echo "Error en login, intentelo mas tarde";
        header("Location:../../login.php?errorCode=3&errorType=1");
               
    }
    
    
    

?>